package org.jin.samples.test;

import java.util.List;

import org.jin.samples.dao.ISubjectDao;
import org.jin.samples.dao.ITestDao;
import org.jin.samples.model.ExamSubject;
import org.jin.samples.model.ExamTest;
import org.jin.samples.model.ExamTestType;
import org.jin.samples.model.vo.ExamTestTypeVO;
import org.jin.samples.model.vo.ExamTestVO;
import org.jin.samples.page.PagerModel;
import org.jin.samples.service.ITestService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({"file:WebContent/WEB-INF/viewspace-servlet.xml"})
public class testDaoImpl {
	
	@Autowired
	private ITestDao testDao;
	
	@Autowired
	private ITestService testService;
	
	@Autowired
	private ISubjectDao subjectDao;
	
	@Test
	public void test() {
		List<ExamTest> examTest = testDao.findAllTest();
		for(ExamTest u : examTest){
			System.out.println("u.getId()="+u.getId()+"      u.getContent()= "+u.getContent()+
					"     u.getExamTestType().getId()="+u.getExamTestType().getId()+
					"           u.getExamTestType().getTestType()= "+u.getExamTestType().getTestType());
			System.out.println("******************");
			System.out.println(""+u.getExamSubject().getName());
		}
	}
	
/*	@Test
	public void Service(){
		ExamTestVO vo = testService.findByTest(27);
		System.out.println("vo.getId()="+vo.getId());
		System.out.println("vo.getExamSubjectVo().getName()="+vo.getExamSubjectVo().getName());
		System.out.println("*****类型*****"+vo.getExamTestTypeVo().getId()+"           "+
		vo.getExamTestTypeVo().getTestType()+"          "+vo.getExamTestTypeVo().getTestTypeScore());
	}
*/
	
	@Test
	public void test4(){
		ExamTest e = testDao.findByTest(27);
			System.out.println("******************");
			System.out.println(e.getContent()+"     ="+e.getId()+"     ="+e.getExamTestType());
		}
	
	@Test
	public void edit(){
		ExamTestVO examTest = new ExamTestVO();
		examTest.setAnswer("1");
		examTest.setChooseA("4");
		examTest.setChooseB("4");
		examTest.setChooseC("4");
		examTest.setChooseD("4");
		examTest.setContent("数学");
		examTest.setId(44);
		ExamSubject es = new ExamSubject();
		es.setSubId(3);
		examTest.setSubId(es.getSubId());
		ExamTestTypeVO ett = new ExamTestTypeVO();
		ett.setId(1);
		examTest.setExamTestTypeVo(ett);
		try {
			testService.editTest(examTest);
			System.out.println("修改成功");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	
	@Test
	public void service(){
		ExamTestVO s= testService.findByTest(27);
		
		System.out.println(s.getName());
	}
	
	
	@Test
	public void service1(){
		ExamTestVO examTest = new ExamTestVO();
		examTest.setAnswer("A");
		examTest.setChooseA("1");
		examTest.setChooseB("2");
		examTest.setChooseC("3");
		examTest.setChooseD("4");
		examTest.setContent("数学");
		ExamTestTypeVO ttvo=new ExamTestTypeVO();
		ttvo.setId(1);
		examTest.setExamTestTypeVo(ttvo);
		examTest.setSubId(1);
		/*ExamTestType tt=new ExamTestType();
		tt.setId(1);
		ExamSubject es = new ExamSubject();
		es.setSubId(1);*/
		
		try {
			testService.addTest(examTest);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.println("添加成功");
	}
	
	
	
	
	
	
	
	@Test
	public void service3(){
		ExamTestVO examTest = new ExamTestVO();
		
		examTest.setAnswer("A");
		examTest.setChooseA("1");
		examTest.setChooseB("2");
		examTest.setChooseC("3");
		examTest.setChooseD("4");
		examTest.setContent("数学");
		examTest.setId(27);
		examTest.setSubId(1);
		ExamTestTypeVO ttvo=new ExamTestTypeVO();
		ttvo.setId(1);
		examTest.setExamTestTypeVo(ttvo);
		examTest.setSubId(1);
		/*ExamTestType tt=new ExamTestType();
		tt.setId(1);
		ExamSubject es = new ExamSubject();
		es.setSubId(1);*/
		
		try {
			testService.editTest(examTest);
			System.out.println("修改成功");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	@Test
	public void service4(){
		ExamTest examTest1 = testDao.findByTest(27);
		ExamTest examTest = new ExamTest();
		examTest.setAnswer("A");
		examTest.setChooseA("1");
		examTest.setChooseB("2");
		examTest.setChooseC("3");
		examTest.setChooseD("4");
		examTest.setContent("数学");
		examTest.setId(27);
		examTest.setId(1);
		ExamTestType ttvo=new ExamTestType();
		ttvo.setId(1);
		examTest.setExamTestType(ttvo);
		examTest.setId(1);
		if(examTest!=null){
			try {
				testDao.editTest(examTest);
				System.out.println("成功");
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
	}	
}
	
	@Test
	public void delete(){
		testService.deleteUser(41);
		System.out.println("成功");
	}
	
	
	@Test
	public void findpage(){
		PagerModel<ExamTest> examTestVO = testDao.findAllByPage();
		for(ExamTest vo : examTestVO.getDates()){
			System.out.println(vo.getAnswer());
			//System.out.println("  ="+vo.getContent()+"  ="+vo.getId());
			//System.out.println("   = "+vo.getExamTestTypeVo().getId()+"    ="+vo.getExamTestTypeVo().getTestType());
		}
	}
	
	@Test
	public void test5(){
		ExamTestVO et= testService.findByTest(4);
		System.out.println("et.getName()="+et.getName());
		System.out.println("et.getExamTestTypeVo().getTestTypeScore()="+et.getExamTestTypeVo().getTestTypeScore());
		System.out.println("et.getSubId()="+et.getSubId());
	}
	
}









